import { DynamicModule, Module } from "@nestjs/common";
import { EmailNoticeService } from "./notice-email.service";
import { SmsNoticeService } from "./notice-sms.service";

export interface NoticeModuleOptions {
    type: 'email' | 'sms';
}

/**
 * NoticeModule is a module that provides notice services.
 * It can be configured to use either email or sms notice services.
 * this is a dynamic module.
 */
@Module({})
export class NoticeModule {
    static forRoot(options: NoticeModuleOptions): DynamicModule {
      const noticeProvider = {
        provide: 'NOTICE_SERVICE',
        useClass: options.type === 'email' ? EmailNoticeService : SmsNoticeService,
      }
      return {
        module: NoticeModule,
        providers: [noticeProvider],
        exports: [noticeProvider],
        global: false,
      }
    }
}